#ifndef _core_switch_detail_next_impl_hpp_
#define _core_switch_detail_next_impl_hpp_

/** \file next_impl.hpp
 *  \author Adrian Schweizer
 *  \created  $Mo 11 Feb 08:33:01 pm CET 2008 schwadri@SchwadriLaptop.local$
 *  \modified $Mo 11 Feb 08:39:02 pm CET 2008 schwadri@SchwadriLaptop.local$
 */

#include <boost/config.hpp>
#include <boost/mpl/void.hpp>
#include <boost/mpl/if.hpp>
#include "../case_iterator.hpp"
#include "../case_sequence.hpp"

namespace boost {
    namespace fusion {
        namespace extension {

            template <typename Tag>
                struct next_impl;

            template <>
                struct next_impl<core::case_iterator_tag>
                {
                    template <typename Iterator>
                        struct apply
                        {
                            typedef typename Iterator::index            index;
                            typedef typename Iterator::case_type        sequence;
                            typedef typename result_of::size<sequence>::type size;
                            BOOST_STATIC_CONSTANT(std::size_t, next_pos =  ((index::value + 1)> size::value) ? size::value : (index::value + 1));
                            /*typedef typename mpl::if_c<(next_pos < size::value),
                                                            sequence,
                                                            mpl::void_
                                                            >::type next_case;
                            */

                            typedef core::case_iterator<sequence,next_pos> type;
                            static type call(const Iterator& iter)
                            {
                                return type(iter.c());
                            }
                        };
            };
        }
    }
}


#endif // _core_switch_detail_next_impl_hpp_
